package extend.client;

import extend.client.base.Method;
import extend.client.base.Request;
import extend.client.base.RequestParams;
import extend.client.base.Response;
import java.util.Map;

/**
 * 网络i/o客户端类
 *<B>说明：</B>
 *<pre>
 * 用于http,tcp 发送请求
 *</pre>
 *<B>示例：</B>
 *<pre>
 *  略
 *</pre>
 *<B>日志：</B>
 *<pre>
 *  略
 *</pre>
 *<B>注意事项：</B>
 *<pre>
 *  略
 *</pre>
 */
public class Client
{

    /** 以下方法未快捷方式*/

    public Response get(String uri)
    {
        Request request = this.createRequestShortcut(Method.GET_METHOD,uri,null,null);
        return request.send();
    }

    public Response get(String uri,Map<String,Object> data)
    {
        Request request = this.createRequestShortcut(Method.GET_METHOD,uri,data,null);
        return request.send();
    }

    public Response post(String uri)
    {
        Request request = this.createRequestShortcut(Method.POST_METHOD,uri,null,null);
        return request.send();
    }

    public Response post(String uri,Map<String,Object> data)
    {
        Request request = this.createRequestShortcut(Method.POST_METHOD,uri,data,null);
        return request.send();
    }

    /**
     * 创建Request
     *<B>说明：</B>
     *<pre>
     * 略
     *</pre>
     */
    public Request createRequest()
    {
        RequestParams requestConfig = new RequestParams(null);
        return requestConfig.createRequest();
    }

    /**
     * 创建Request
     *<B>说明：</B>
     *<pre>
     * 略
     *</pre>
     */
    public Request createRequest(Map<String,Object> options)
    {
        RequestParams requestConfig = new RequestParams(options);
        return requestConfig.createRequest();
    }

    public Request createRequest(RequestParams requestParams)
    {
        return requestParams.createRequest();
    }

    /**
     * 创建Request 快捷方法
     *<B>说明：</B>
     *<pre>
     * 略
     *</pre>
     */
    public Request createRequestShortcut(String method,String uri,Map<String,Object> data,Map<String,Object> options)
    {
        RequestParams requestConfig = new RequestParams(options);
        requestConfig.setMethod(method);
        Request request = this.createRequest(requestConfig);
        request.setUri(uri);
        request.setData(data);

        return request;
    }

    public Response send(Request request)
    {
        return request.send();
    }
}
